package com.zhkj.txg.module.home.popup

import android.app.Application
import android.view.View
import android.widget.TextView
import androidx.core.text.buildSpannedString
import androidx.core.text.scale
import com.zhkj.txg.R
import com.zhkj.txg.module.mine.entity.CouponEntity
import razerdp.basepopup.BasePopupWindow

class NewCouponPopupWindow(application: Application) : BasePopupWindow(application) {
    override fun onCreateContentView(): View = createPopupById(R.layout.popup_new_coupon)

    private var tvNewCouponName: TextView? = null
    private var tvNewCouponUseType: TextView? = null
    private var tvNewCouponArea: TextView? = null

    override fun onViewCreated(contentView: View?) {
        tvNewCouponName = findViewById(R.id.tvNewCouponName)
        tvNewCouponUseType = findViewById(R.id.tvNewCouponUseType)
        tvNewCouponArea = findViewById(R.id.tvNewCouponArea)
        contentView?.setOnClickListener { dismiss() }
    }

    fun setData(coupon: CouponEntity) {
        tvNewCouponName?.text = buildSpannedString {
            append("￥")
            scale(2F) { append(coupon.money.toString()) }
            append("优惠券")
        }
        tvNewCouponUseType?.text = coupon.typeText
        tvNewCouponArea?.text = coupon.areaTypeText
    }
}